package com.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;

import org.junit.Test;

import com.model.Student;


public class StuService {
	
	public static List<Student> getAllByExcel(String file){
		 List<Student> list=new ArrayList<Student>();
	        try {
	            Workbook rwb=Workbook.getWorkbook(new File(file));
	            //Sheet rs=rwb.getSheet("Test Shee 1");//或者rwb.getSheet(0)
	           Sheet rs=   rwb.getSheet(0);
	            int clos=rs.getColumns();//得到所有的列
	            int rows=rs.getRows();//得到所有的行
	            
	            System.out.println(clos+" rows:"+rows);
	            for (int i = 1; i < rows; i++) {
	                for (int j = 0; j < clos; j++) {
	                    //第一个是列数，第二个是行数
	                    String xuehao=rs.getCell(j++, i).getContents();//默认最左边编号也算一列 所以这里得j++
	                    String xiaoqu=rs.getCell(j++, i).getContents();
	                    String yuanxi=rs.getCell(j++, i).getContents();
	                    String zhuanye=rs.getCell(j++, i).getContents();
	                    String banji=rs.getCell(j++, i).getContents();
	                    String xingming=rs.getCell(j++, i).getContents();
	                    String xingbie=rs.getCell(j++, i).getContents();
	                    String mingzhu=rs.getCell(j++, i).getContents();
	                    String mianmao=rs.getCell(j++, i).getContents();
	                //   System.out.println(xuehao); 
	                  //  System.out.println("id:"+id+" name:"+name+" sex:"+sex+" num:"+num);
	                    list.add(new Student(xuehao, xiaoqu, yuanxi, zhuanye, banji, xingming, xingbie, mingzhu, mianmao));
	                  //  System.out.println(list.size()); 
	                }
	            }
	        } catch (Exception e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        } 
	        System.out.println(list.size()); 
	        return list;
}
}
